<!--
  Copyright 2019 Hackware SpA <human@hackware.cl>
  This file is part of "Hackware Userland" and licensed under the terms
  of the GNU Affero General Public License version 3, or (at your option)
  a later version. You should have received a copy of this license along
  with the software. If not, see <https://www.gnu.org/licenses/>.
-->

<template>
  <input
    :type="type"
    :name="name"
    :value="property.default"
    :readonly="readonly"
    class="form-control"
  >
</template>

<script>
export default {
  name: 'SchemaFormInputWidget',
  props: {
    name: {
      type: String,
      required: true,
    },
    property: {
      type: Object,
      required: true,
    },
    readonly: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    type() {
      let type;
      switch (this.property.type) {
        case 'number':
        case 'integer':
          type = 'number';
          break;
        case 'string':
          if (('format' in this.property) && this.property.format.includes('email')) {
            type = 'email';
          } else {
            type = 'text';
          }
          break;
        default:
          throw ReferenceError('Unsupported input property, must be type "number", "integer" or "string"');
      }
      return type;
    },
    // TODO: Implement step
  },
};
</script>
